<template>
  <div class="container">
    <CommonHeader bgImage="https://ik.imagekit.io/mpjl8xreo/sort.png">
      <h1 class="title">归档</h1>
    </CommonHeader>
    <div class="sort-container">
      <List
        :List="SortList"
        :Pagination="true"
        :page="page"
        :pageSize="pageSize"
        @changePage="changePage"
        @changeRoute="changeRoute"
      >
        <template v-slot:content="{ item }">
          <img :src="item['cover']" alt="" style="width: 100%; height: 180px" />
          <div class="card-info">
            <h1>{{ item["name"] }}</h1>
            <p class="info-more">
              <span
                >创建日期：
                {{ dayjs(item.createDate).format("YYYY-MM-DD") }}</span
              >
              <span>
                共
                <i style="color: skyblue; margin: 0 5px">{{ item.total }}</i>
                篇博客</span
              >
            </p>
          </div>
        </template>
      </List>
    </div>
  </div>
</template>
<script setup>
import List from "@/components/List/index.vue";
import { getCurrentInstance, ref } from "vue";
import CommonHeader from "@/components/CommonHeader/index.vue";
import { getAllSort } from "@/api/sort.js";
import router from "@/router/index.js";
import dayjs from "dayjs";

const { proxy } = getCurrentInstance();
let total = ref(1);
let pageSize = ref(5);
let page = ref(1);
let SortList = ref([]);
const getSortList = async () => {
  let res = await getAllSort();
  if (res && res.status === 200) {
    total.value = res.total;
    pageSize.value = res.pageSize;
    page.value = res.page;
    SortList.value = res.data;
  }
};
// 切换分页
const changePage = (val) => {
  getSortList({ page: val });
};

const changeRoute = (id) => {
  router.push("/sortDetail/" + id);
};
getSortList();
</script>
<style lang="scss" scoped>
@mixin ellipsis {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.container {
  width: 100%;
  height: 100%;
  overflow: hidden;

  .title {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    text-align: center;
    font-size: 40px;
    color: #ffff;
    font-weight: bold;
  }

  .sort-container {
    width: 100%;

    animation: profile_in 0.8s;

    .card-info {
      width: 100%;
      padding: 15px;
      display: flex;
      flex-direction: column;
      gap: 5px;
      background-color: #fafafa;

      h1 {
        width: 100%;
        font-size: 16px;
        color: #606266;
        @include ellipsis;
      }

      p {
        width: 100%;
        font-size: 12px;
        color: #a8abb2;
        display: flex;
        justify-content: space-between;
      }
    }
  }
}

:deep(.el-card__body) {
  padding: 0 !important;
}
</style>
